//定义数据
const fLiArr = [
  {
    id: 0,
    url: "./page/home_page/home.html",
    name: "首页",
    icon: "iconfont icon-shouye",
  },
  {
    id: 1,
    url: "javascript:",
    name: "系统管理",
    icon: "iconfont icon-xitongguanli-",

    item: [
      { id: 0, url: "./page/System_m/rygl.html", name: "人员管理" },
      { id: 1, url: "./page/System_m/jsgl.html", name: "角色管理" },
      { id: 2, url: "./page/System_m/cdgl.html", name: "菜单管理" },
      { id: 3, url: "./page/System_m/bmgl.html", name: "部门管理" },
      { id: 4, url: "./page/System_m/zwgl.html", name: "职务管理" },
      { id: 5, url: "./page/System_m/wdbm.html", name: "我的部门" },
    ],
  },
  {
    id: 2,
    url: "javascript:",
    name: "订单管理",
    icon: "iconfont icon-dingdanguanli",
    item: [
      { id: 0, url: "./page/order_m/ypdd.html", name: "药品订单" },
      { id: 1, url: "./page/order_m/wzdd.html", name: "问诊订单" },
    ],
  },
  {
    id: 3,
    url: "./page/drug.m/ypgl.html",
    name: "药品管理",
    icon: "iconfont icon-houtaitubiao-09",
  },
  {
    id: 4,
    url: "./page/disease_m/disease.html",
    name: "疾病管理",
    icon: "iconfont icon-jibingguanli",
  },
  {
    id: 5,
    url: "./page/article_m/article.html",
    name: "文章管理",
    icon: "iconfont icon-navicon-wzgl",
  },
  {
    id: 6,
    url: "./page/experts_m/experts.html",
    name: "专家管理",
    icon: "iconfont icon-Icon-zhuanjiaguanli",
  },
  {
    id: 7,
    url: "javascript:",
    name: "用户管理",
    icon: "iconfont icon-yonghuguanli",
    item: [
      { id: 0, url: "./page/user_m/yhlb.html", name: "用户列表" },
      { id: 1, url: "./page/user_m/jkda.html", name: "健康档案" },
    ],
  },
  {
    id: 8,
    url: "./page/prescription_m/prescription.html",
    name: "处方管理",
    icon: "iconfont icon-shishichufangguanli",
    item: [{ id: 0, url: "./page/user_m/yhgl.html", name: "处方列表" }],
  },
  {
    id: 9,
    url: "./page/department_m/ksgl.html",
    name: "科室管理",
    icon: "iconfont icon-keshiguanli",
  },
  {
    id: 10,
    url: "./page/hospital_m/yygl.html",
    name: "医院管理",
    icon: "iconfont icon-yiyuanguanli",
  },
  {
    id: 11,
    url: "javascript:",
    name: "财务结算",
    icon: "iconfont icon-caiwujiesuan",
    item: [
      { id: 0, url: "./page/financial_m/txjl.html", name: "提现记录" },
      { id: 1, url: "./page/financial_m/jsjl.html", name: "结算记录" },
    ],
  },
  {
    id: 12,
    url: "./page/comments_m/comments.html",
    name: "评论管理",
    icon: "iconfont icon-pinglunguanli",
  },
  {
    id: 13,
    url: "javascript:",
    name: "配设管理",
    icon: "iconfont icon-shebeiguanli",
    item: [
      { id: 0, url: "./page/equipment_m/ptsz.html", name: "平台设置" },
      { id: 1, url: "./page/equipment_m/wzsz.html", name: "问诊设置" },
    ],
  },
  {
    id: 14,
    url: "./page/advertising_m/advertising.html",
    name: "广告管理",
    icon: "iconfont icon-ad-manage",
  },
  {
    id: 15,
    url: "javascript:",
    name: "系统监控",
    icon: "iconfont icon-xitongjiankong",
    item: [
      { id: 0, url: "./page/monitor_m/redis.html", name: "redis" },
      { id: 1, url: "./page/monitor_m/fwqxx.html", name: "服务器信息" },
      { id: 2, url: "./page/monitor_m/qqzz.html", name: "请求追踪" },
    ],
  },
]

//展示一级菜单
showNavFli(fLiArr)
function showNavFli(arr) {
  arr.forEach((ele) => {
    $(".nav-l .list-group>ul").append(
      `<li>
            <a  data-name="${ele.name}" data-url="${ele.url}" class="list-group-item">
            <span class="${ele.icon}"></span>
            ${ele.name}
            </a>
        </li>`
    )
  })
}

// 获取需要渲染的二级菜单
const sLiArr = []
selectEl(fLiArr)
function selectEl(arr) {
  arr.forEach((ele, i) => {
    if (ele.url === "javascript:") {
      sLiArr.push(arr[i])
    }
  })
}

//渲染二级菜单
for (let i = 0; i < sLiArr.length; i++) {
  $(".nav-l .list-group>ul>li")
    .eq(sLiArr[i].id)
    .append(`<ul class="second-list"></ul>`)
  if (sLiArr[i].item !== undefined) {
    //渲染每个二级菜单
    sLiArr[i].item.forEach((ele) => {
      $(".nav-l .list-group>ul>li")
        .eq(sLiArr[i].id)
        .children("ul")
        .append(
          `<li>
             <a  data-name="${ele.name}" data-url="${ele.url}" class="list-group-item">
            ${ele.name}
            </a>
          </li>`
        )
    })
  }
}

// 侧边栏动画
$(".nav-l .list-group>ul>li>a").on("click", function () {
  console.log($(this).next().length)
  if ($(this).next().length === 0) {
    $(".nav-l .list-group>ul>li>a").removeClass("active")
    $(".nav-l .list-group>ul>li").css("height", "50px")
    let h = ($(this).siblings().children().length + 1) * 50 + "px"
    $(this).parent().css("height") === "50px"
      ? $(this).toggleClass("active").parent().css("height", h)
      : $(this).toggleClass("active").parent().css("height", "50px")
  } else {
    $(".nav-l .list-group>ul>li").css("height", "50px")
    let h = ($(this).siblings().children().length + 1) * 50 + "px"
    $(this).parent().css("height") === "50px"
      ? $(this).parent().css("height", h)
      : $(this).parent().css("height", "50px")
  }
})

//默认渲染首页
//load --------加载有问题--改了
// $(".main-connect").load($(".nav-l .list-group>ul>li>a").eq(0).attr("data-url"))
$(".main-connect").append(
  `<iframe src="${fLiArr[0].url}" width="100%" height="100%" frameborder="0"></iframe>`
)
$(".nav-l>.list-group>ul>li>a").eq(0).addClass("active")
$(".header-nav>.breadcrumb").append(`<li><a>首页</a></li>`)

//一级菜单 绑定点击事件显示点击页面
$(".nav-l>.list-group>ul>li>a").on("click", function () {
  $(".nav-l>.list-group>ul>li a").removeClass("a-active")
  const url = $(this).attr("data-url")
  const name = $(this).attr("data-name")
  if (url !== "javascript:") {
    $(".main-connect").html("")
    $(".header-nav>.breadcrumb").html("")
    $(".main-connect").append(
      `<iframe src="${url}" width="100%" height="100%" frameborder="0"></iframe>`
    )
    $(this).addClass("a-active")
    $(".header-nav>.breadcrumb").append(`<li><a>${name}</a></li>`)
  }
})
//二级菜单 绑定点击事件显示点击页面
$(".nav-l>.list-group>ul>li>ul a").on("click", function () {
  $(".nav-l>.list-group>ul>li a").removeClass("a-active")
  $(".header-nav>.breadcrumb").html("")
  const url = $(this).attr("data-url")
  const nameF = $(this).parent().parent().prev().attr("data-name")
  const nameS = $(this).attr("data-name")
  if (url !== "javascript:") {
    $(".main-connect").html("")
    $(".main-connect").append(
      `<iframe src="${url}" width="100%" height="100%" frameborder="0"></iframe>`
    )
    $(this).addClass("a-active")
    $(".nav-l>.list-group>ul>li a").removeClass("active")
    $(this).parent().parent().prev().addClass("active")
  }
  $(".header-nav>.breadcrumb").append(
    `
    <li><a>${nameF}</a></li>
    <li><a>${nameS}</a></li>
    `
  )
})
//测边栏隐藏
$("#show-btn").on("click", function () {
  $(".nav-l").toggleClass("dis-none col-md-2 col-xs-2 col-md-0 col-xs-0")
  $(".show-wrap").toggleClass("col-md-10 col-xs-10 col-md-12 col-xs-12")
})

//登录中心

//登录动画
$(".login").hover(
  function () {
    $(".drown-wrap").css("top", "65px").toggleClass("login-active")
  },
  function () {
    $(".drown-wrap").css("top", "-100px").toggleClass("login-active")
  }
)
//展示登录信息
const user = JSON.parse(localStorage.getItem("user"))
console.log(user)
$(".login>a").text(`${user.name}`)
